Imports System.ComponentModel

Public Class AnalogGauge
    Inherits System.Windows.Forms.UserControl

    Private moGauge As clsAnalogGauge

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

        'Add any initialization after the InitializeComponent() call
        Dim iDiameter As Integer
        If Me.Width < Me.Height Then
            iDiameter = Me.Width - 2
        Else
            iDiameter = Me.Height - 2
        End If

        moGauge = New clsAnalogGauge( _
            Me, _
            iDiameter, _
            Me.Width / 2, _
            Me.Height / 2, _
            0, _
            100)
    End Sub

    'UserControl1 overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'AnalogGauge
        '
        Me.Name = "AnalogGauge"

    End Sub

#End Region

    Private Sub AnalogGauge_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        moGauge.Draw(e.Graphics)
    End Sub


    Protected Overrides Sub Finalize()
        moGauge = Nothing

        MyBase.Finalize()
    End Sub

    Private Sub AnalogGauge_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Dim iDiameter As Integer
        If Me.Width < Me.Height Then
            iDiameter = Me.Width - 2
        Else
            iDiameter = Me.Height - 2
        End If

        moGauge.X = Me.Width / 2
        moGauge.Y = Me.Height / 2
        moGauge.Diameter = iDiameter
    End Sub

    <Description("Minimum value of gauge")> _
        Public Property MinValue() As Integer
        Get
            Return moGauge.StartNumber()
        End Get
        Set(ByVal Value As Integer)
            moGauge.StartNumber() = Value
        End Set
    End Property

    <Description("Maximum value of gauge")> _
    Public Property MaxValue() As Integer
        Get
            Return moGauge.EndNumber
        End Get
        Set(ByVal Value As Integer)
            moGauge.EndNumber = Value
        End Set
    End Property

    <Description("Current value of gauge")> _
        Public Property Value() As Integer
        Get
            Return moGauge.Value
        End Get
        Set(ByVal Value As Integer)
            moGauge.Value = Value
        End Set
    End Property

    <Description("Display box around displayed value")> _
    Public Property ShowBox() As Boolean
        Get
            Return moGauge.ShowBoxes
        End Get
        Set(ByVal Value As Boolean)
            moGauge.ShowBoxes = Value
        End Set
    End Property

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        '---Don't do anything
    End Sub
End Class
